<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>班级名单</title>
    <style type="text/css">
        #tab {
            margin: 0px auto;
            width: 500px;
            height: 500px;

        }

        td {
            border: solid 2px red;
            width: 100px;
            height: 70px;
            text-align: center;
            font-weight: bold;
        }
    </style>

    <script>
        var tim = 0;
        var st;
        
        function fn() {
            tim++;
            for (let i = 1; i <= 42; i++) {
                var tdobj = document.getElementById('td' + i);
                tdobj.style.backgroundColor = 'white';
            }
            var num = parseInt(Math.random() * 41 + 1)
            var tdobj = document.getElementById('td' + num);
            tdobj.style.backgroundColor = 'blue';
            if (tim >= 30) {
                //将结果显示到span中
                document.getElementById('cr').innerText =  tdobj.innerText;
                clearInterval(st);
            }
        }

        function start() {
            tim = 0
            for (let i = 1; i <= 42; i++) {
                var tdobj = document.getElementById('td' + i);
                tdobj.style.backgroundColor = 'white';
            }
            document.getElementById('cr').innerText = '正在抽人...';
            st = setInterval(fn,100);
        }
    </script>
</head>
<body>
    <div id="btn" style="text-align: center; margin:50px">
        <button onclick="start()">点击抽奖</button>
        <span id="cr"></span>
    </div>
    <table id="tab">
        <tr>
            <td id="td1">李韦峰</td>
            <td id="td2">卢国建</td>
            <td id="td3">郑玮喆</td>
            <td id="td4">占志新</td>
            <td id="td5">陈梅香</td>
            <td id="td6">廖治先</td>
        </tr>
        <tr>
            <td id="td7">廖柏成</td>
            <td id="td8">李涛</td>
            <td id="td9">陈昊童</td>
            <td id="td10">陈华伟</td>
            <td id="td11">郑文源</td>
            <td id="td12">郑宗帅</td>
        </tr>
            <td 2d="td13">陈立智</td>
            <td id="td14">刘永潘</td>
            <td id="td15">吴文龙</td>
            <td id="td16">陈鹏</td>
            <td id="td17">王世财</td>
            <td id="td18">庄云</td>
        </tr>
        <tr>
            <td id="td19">杨凌翔</td>
            <td id="td20">林世涛</td>
            <td id="td21">张淑芳</td>
            <td id="td22">戴俊锋</td>
            <td id="td23">谢金金</td>
            <td id="td24">赵浩敏</td>
        </tr>
        <tr>
            <td id="td25">袁贵森</td>
            <td id="td26">黄雄</td>
            <td id="td27">吴欣燕</td>
            <td id="td28">陆利群</td>
            <td id="td29">罗此东</td>
            <td id="td30">韦仲晓</td>
        </tr>
        <tr>
            <td id="td31">黄富贵</td>
            <td id="td32">张正豪</td>
            <td id="td33">张先杰</td>
            <td id="td34">陆建锋</td>
            <td id="td35">张耀仁</td>
            <td id="td36">胡基耀</td>
        </tr>
        <tr>
            <td id="td37">唐皓颖</td>
            <td id="td38">罗启恒</td>
            <td id="td39">马鑫涛</td>
            <td id="td40">曾德森</td>
            <td id="td41">黄柱菘</td>
            <td id="td42">无</td>
        </tr>
    </table>
</body>
</html>